package com.xxcloud.model.web;

public class PageManager {

    private int totalRecords = 0;
    private int oneTimeNum = 300;
    private int currentFirst = -1;
    private int pageNo = 0;

    public PageManager(int t) {
        this.totalRecords = t;
    }

    public PageManager(int total, int perNum) {
        this.totalRecords = total;
        this.oneTimeNum = perNum;
    }

    public boolean hasNextPage() {
        if (currentFirst < 0) {
            currentFirst = 0;
        } else {
            currentFirst += oneTimeNum;
        }
        pageNo++;
        return currentFirst < totalRecords;
    }

    public int getFirst() {
        return currentFirst;
    }

    public int getMax() {
        return oneTimeNum;
    }

    public int getToIndex() {
        long temp = currentFirst + oneTimeNum;
        return (int) Math.min(temp, totalRecords);
    }

    public int getPageNo() {
        return pageNo;
    }

    public static void main(String[] args) {
        PageManager pm = new PageManager(54000, 10000);
        while (pm.hasNextPage()) {
            System.out.println(pm.getPageNo() + ":" + pm.getFirst() + ":" + pm.getMax());
        }
    }
}
